﻿868.二进制间距
int binaryGap(int n) {
    int ans = 0, pos = -1;
    for (int i = 0; i < 32; i++)
    {
        if ((n >> i) & 1 == 1)
        {
            if (pos != -1)
            {
                ans = ans > i - pos ? ans : i - pos;
            }
            pos = i;
        }
    }
    return ans;
}

//---------------------------------------------------------------------------------------------------

//（牛客网）
//KY258 日期累加
#include <iostream>
using namespace std;
int getmonthday(int year, int month)
{
    int monthday[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
    if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
    {
        return 29;
    }
    return monthday[month];
}

int main() {
    int year, month, day, day_add;
    int m;
    cin >> m;

    while (m--)
    {
        cin >> year >> month >> day >> day_add;
        day += day_add;
        while (day > getmonthday(year, month))
        {
            day -= getmonthday(year, month);
            month++;
            if (month == 13)
            {
                month = 1;
                year++;
            }
        }
        cout << year << "-" << month / 10 << month % 10 << "-" << day / 10 << day % 10 << endl;
    }

}

//KY222 打印日期
#include <iostream>
using namespace std;
int getmonthday(int year, int month) {
    int monthday[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) {
        return 29;
    }
    return monthday[month];
}

int main() {
    int year, day;
    while (cin >> year >> day) {
        int month = 1;
        while (day > getmonthday(year, month)) {
            day -= getmonthday(year, month);
            month++;
            if (month == 13) {
                month = 1;
                year++;
            }
        }
        cout << year << "-" << month / 10 << month % 10 << "-" << day / 10 << day % 10
            << endl;

    }
}

